<?php 
 include_once dirname(__FILE__)."/config.php";
 class ens_ue_principal{
		 protected $_result;
		 protected $_cnn;
		 protected $_code_ens;
		 protected $_code_ue;
		 protected $_role;
		 protected $_code_etab_rattach;
		 protected $_nbr_ens;
		 public function get_name_table(){ return "ens_ue";}
		 public function get_name_code_ens(){ return "code_ens";}
		 public function get_name_code_ue(){ return "code_ue";}
		 public function get_name_role(){ return "role";}
		 public function get_name_code_etab_rattach(){ return "code_etab_rattach";}
		 public function get_name_nbr_ens(){ return "nbr_ens";}
		 public function set_code_ens($parametre){  $this->_code_ens=$parametre;}	
		 public function set_code_ue($parametre){  $this->_code_ue=$parametre;}	
		 public function set_role($parametre){  $this->_role=$parametre;}	
		 public function set_code_etab_rattach($parametre){  $this->_code_etab_rattach=$parametre;}	
		 public function set_nbr_ens($parametre){  $this->_nbr_ens=$parametre;}	
		 public function get_result(){ return $this->_result;}
		 public function get_code_ens(){ return $this->_code_ens;}
		 public function get_code_ue(){ return $this->_code_ue;}
		 public function get_role(){ return $this->_role;}
		 public function get_code_etab_rattach(){ return $this->_code_etab_rattach;}
		 public function get_nbr_ens(){ return $this->_nbr_ens;}
public function __construct(){

		 	$this->_cnn=new databaseconnect();

		 }

 public function INSERT()
{

$sql=" INSERT INTO 
 ens_ue(
			code_ens,
			code_ue,
			role,
			code_etab_rattach,
			nbr_ens)
 VALUES(
			'".$this->_code_ens."',
			'".$this->_code_ue."',
			'".$this->_role."',
			'".$this->_code_etab_rattach."',
			'".$this->_nbr_ens."')";
//echo $sql;
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function UPDATE()
{

 $sql="";
if(!empty($this->_code_ens)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_ens='".$this->_code_ens."'";
}
if(!empty($this->_code_ue)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_ue='".$this->_code_ue."'";
}
if(!empty($this->_role)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
role='".$this->_role."'";
}
if(!empty($this->_code_etab_rattach)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
code_etab_rattach='".$this->_code_etab_rattach."'";
}
if(!empty($this->_nbr_ens)){
	if(!empty($sql)){$sql.=",";}
$sql.="		
nbr_ens='".$this->_nbr_ens."'";
}
$sql="UPDATE 
ens_ue SET 
 ".$sql."
								WHERE  ='".$this->_."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function DELETE(){

 $sql="DELETE FROM 
ens_ue 
 
									WHERE  ='".$this->_."'";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function TRANCATE(){

 $sql="DELETE FROM 
ens_ue ";

$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}

 public function SELECT($constraint="",$pagination="")
{

$sql=" SELECT 
 		code_ens,
		code_ue,
		role,
		code_etab_rattach,
		nbr_ens
 FROM 
 ens_ue";
if($constraint){$sql.=" WHERE 1=1 ".$constraint;}if($pagination){$sql.=$pagination;}
$this->_result=$this->_cnn->query($sql);
 if(!$this->_result){return 'erreur d\'execution de la requette';}else{return 'success';}
}
public function fetch_object(){
$row=mysql_fetch_object($this->_result);
 if($this->_result){
 if($row){
		$this->_code_ens=$row->code_ens;
		$this->_code_ue=$row->code_ue;
		$this->_role=$row->role;
		$this->_code_etab_rattach=$row->code_etab_rattach;
		$this->_nbr_ens=$row->nbr_ens;
		return $row;
		}else{
					return false;
				}

			}else{
				//echo 'Erreur d\'execution de requette de selection';	
			}
			

		}

}
?>